package cn.wikiflyer.beikang.act.user.setting;

import net.tsz.afinal.annotation.view.ViewInject;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import cn.wikiflyer.beikang.BaseActivity;
import cn.wikiflyer.beikang.R;
import cn.wk.libs4a.net.WKAsyncTaskPro;
import cn.wk.libs4a.utils.WKCountDownUtils;

/** @author maizi
 * UserSettingModifyNameAct.java
 * 修改手机号
 */
public class UserSettingModifyPhoneAct extends BaseActivity {
	
	@ViewInject(id = R.id.et_name)
	private EditText et_name;
	@ViewInject(id = R.id.find_get_codebtn)
	private Button btn_code;
	@ViewInject(id = R.id.et_code)
	private EditText et_code;
	@ViewInject(id = R.id.modify_commit)
	private Button btn_commit;
	
	private WKCountDownUtils cdUtils = null;

	@Override
	public void loadXml() {
		setContentView(R.layout.bk_act_user_modify_phone);
	}

	@Override
	public void init() {
		cdUtils = new WKCountDownUtils(btn_code, "获取验证码", 600, 1);
		btn_commit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (checkEmpty()) {
					new ModifyPhoneTask(ctx);
				}
			}
		});
		btn_code.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				cdUtils.start();
			}
		});
		
	}

	@Override
	public void setData() {
	}
	/** 检查是否为空，  为空返回false
	 */
	private boolean checkEmpty(){
		if (TextUtils.isEmpty(et_name.getText().toString())||TextUtils.isEmpty(et_code.getText().toString())) {
			Toast.makeText(ctx, "手机号不能为空", Toast.LENGTH_SHORT).show();
			return false;
		}
		return true;
	}
	/** @author maizi
	 * 修改手机号的线程
	 */
	class ModifyPhoneTask extends WKAsyncTaskPro{
		public ModifyPhoneTask(Context context) {
			super(context);
		}
		@Override
		protected String doInBackground(boolean... params) {
			return app().net.modifyPhone();
		}
		@Override
		protected void doOnPostExecute(String result, boolean isLocal) {
		}
	}

}
